package com.example.servlet.integration.restclient.httpinterface;

import org.aspectj.apache.bcel.util.Repository;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.*;

@HttpExchange(url = "/repos/{owner}/{repo}", accept = "application/vnd.github.v3+json")
public interface RepositoryService {

    @GetExchange("/find")
    Repository getRepository(@PathVariable String owner, @PathVariable String repo);

    @PostExchange(contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    void createRepository(@PathVariable String owner, @PathVariable String repo,
                          @RequestParam String name, @RequestParam String description, @RequestParam String homepage);

    @PutExchange(contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    void updateRepository(@PathVariable String owner, @PathVariable String repo,
                          @RequestParam String name, @RequestParam String description, @RequestParam String homepage);

    @DeleteExchange
    void deleteRepository(@PathVariable String owner, @PathVariable String repo);

    // more HTTP exchange methods...
}


// Spring框架允许你将HTTP服务定义为一个Java接口，并为 HTTP exchange 提供注解方法。
// 然后你可以生成一个实现该接口并执行 exchange 的代理。这有助于简化HTTP远程访问，
// 因为远程访问通常涉及到一个 facade，该 facade 包装了使用底层HTTP客户端的细节。

// 创建一个代理，执行所声明的 HTTP exchange：